var pageCount = 1;
function classOnload(a){
    console.log(a);

var Json={
    pageSize:9,
    pageIndex:a,
    fileType:1//0预备1在习
}
ajax.post(ajax.myUrl+"stu/studentList",Json,function(result){
    console.log(result);
    response(result);
    var data = result.dataset.studentList;
    var tbody = document.querySelector("tbody");
    var myarr = [];
    for(var i=0;i<data.length;i++){
        var newtr = document.createElement("tr");
        newtr.innerHTML=`
        <td>${data[i].fileName}</td>
        <td>${data[i].fileSex}</td>
        <td>${data[i].clazzName}</td>
        <td>${data[i].fileDate}</td>
        <td>${data[i].filePhone}</td>
        <td>${data[i].fileStatus}</td>
        <td>
            <div class="remove" id="${data[i].fileId}">修改</div>
            <div class="delete">删除</div>
        </td>
        `;
        tbody.appendChild(newtr)
        myarr.push(data[i].fileId);
        // newtd9.setAttribute("id",result.dataset.clazzList[i].clazzId)
       
    }
    // console.log(myarr);
    // 将学生id以数组的形式存放在本地
    localStorage.setItem("fileId",myarr);
    // 点击修改
    // 
        
        var removes = document.querySelectorAll(".remove");
        var addstudying1 = document.querySelectorAll(".addstudying1")[0];//console.log(addstudying1);
        for(var i=0;i<removes.length;i++){
            localStorage.setItem("fileIds","");
            removes[i].onclick = function(event){
                for(var j=0;j<removes.length;j++){
                    if(this == removes[j]){
                        // console.log(addstudying1);
                        // 模态框显示
                        addstudying1.style.display = "block";
                        // 获取到本条数据
                        // console.log(data[j]);
                        // 将姓名默认显示到修改页面
                        var username =  addstudying1.querySelector("input");
                        username.value=data[j].fileName;
                        // localStorage.setItem("fileNames",data[j].fileName);
                        localStorage.setItem("fileIds",data[j].fileId);
                        var date = new Date();
                        var month = date.getMonth();
                        if(month<9){
                            month = "0"+(month+1);  //月
                        }
                        var day = date.getDate();
                        var num = Math.floor(Math.random()*100);
                        if(num<10){
                            num = "0"+num;  //月
                        }
                        // //获取账号框
                        var number1 = document.getElementsByClassName("number1")[0];
                        //console.log("br"+month+day+num);
                        number1.innerHTML = "br"+month+day+num;
                       }
                    }
            }
         }
            //点击删除用户
            var deletes = document.getElementsByClassName("delete");
            // console.log(deletes);
            // deletes[0].onclick=function(){
            //     console.log(1)
            // }
            for(var j=0;j<deletes.length;j++){
                deletes[j].onclick=function(){
                    for(var k=0;k<deletes.length;k++){
                        if(this==deletes[k]){
                            // console.log(data[k].clazzId)
                            // console.log(data[k].fileId)
                            // console.log(data[k].fileType)
                            var Json4={
                                clazzId: data[k].clazzId,
                                fileId: data[k].fileId,
                                fileType:1
                            }
                            ajax.post(ajax.myUrl+"stu/deleteStu",Json4,function(result){

                            })
                        }
                    }
                }
            }
    //点击修改用户模态框中的确定或取消，模态框消失
    //点击确定
        var sure1 = addstudying1.getElementsByClassName("sure1");
        //    console.log(sure1);
        //    console.log(document.querySelector(".addstudyingContent1").querySelector("select"))
   
           sure1[0].onclick = function(){
            clazzIds=null;
            var select=document.querySelector(".updateStudent");
            var updateStudentSex = document.getElementById("updateStudentSex");
            // console.log(updateStudentSex.value)
            // console.log(select.value);
            if(select.value=="JAVA班"){
                clazzIds="1"
            }else if(select.value=="ui"){
                clazzIds="2"
            }else if(select.value=="python"){
                clazzIds="4"
            }
            // console.log(localStorage.getItem("fileIds"))
            
               var Json3 = {
                   fileId:Number(localStorage.getItem("fileIds")),
                   fileName:document.querySelectorAll("input")[7].value,
                   fileSex:updateStudentSex.value,
                   clazzId:Number(clazzIds),
                   fileDate:document.querySelectorAll("input")[8].value,
                   filePhone:Number(document.querySelectorAll("input")[9].value),
                   fileType:1,
                   fileStuAccount:"21"
               }
               console.log(Json3)
               ajax.post(ajax.myUrl+"stu/updateStu",Json3,function(result){
                   console.log(result);
               }) 
             
               addstudying1.style.display = "none";
        }
        ///搜索用户
       
          
           var cancel1 = addstudying1.getElementsByClassName("cancel1")[0];
           cancel1.onclick = function(){
               addstudying1.style.display = "none";
           }
          

})
  
}
   

// 鼠标经过加号显示要添加的内容
var addition = document.getElementsByClassName("addition")[0];
//加号
var addi = addition.getElementsByClassName("addi")[0];
//要显示的内容
var add = addition.getElementsByClassName("add")[0];
addi.onmouseover = function(){
    add.style.display = "block";
}
addi.onmouseout = function(){
    add.style.display = "none";
}
// //点击加号添加预招生，弹出模态框
// //获取模态框
var addstudying = document.getElementsByClassName("addstudying")[0];

//加号
var addi = addition.getElementsByClassName("addi")[0];
addi.onclick = function(){
    addstudying.style.display = "block";
     // //添加用户模态框中的账号
     var date = new Date();
     var month = date.getMonth();
     if(month<9){
         month = "0"+(month+1);  //月
     }
     var day = date.getDate();
     var num = Math.floor(Math.random()*100);
     if(num<10){
         num = "0"+num;  //月
     }
     // //获取账号框
     var number = document.getElementsByClassName("number")[0];
     //console.log("br"+month+day+num);
     number.innerHTML = "br"+month+day+num;
}
//点击添加预招生模态框中的确定或取消，模态框消失
var sure = addstudying.getElementsByClassName("sure")[0];
sure.onclick = function(){
    addstudying.style.display = "none";
    // console.log( addstudying.querySelectorAll("input"))
    var arr=[];
    var classID=null;
    var inputs = addstudying.querySelectorAll("input");
    var select = addstudying.querySelectorAll("select");
    // console.log(select.value)
    for(var i=0;i<inputs.length;i++){
        arr[i]=inputs[i].value;
    }
    if(select[0].value=="JAVA班"){
        classID=1;
    }else if(select[0].value=="ui"){
        classID=2;
    }else if(select[0].value=="python"){
        classID=4;
    }else if(select[0].value=="前端"){
        classID=6;
    }
    // console.log(classID);
    // console.log(arr)
    var number = document.getElementsByClassName("number")[0];
    var Json2={
        // fileId:localStorage.getItem("fileId"),
        fileName:arr[0],//学生姓名
        fileSex:select[1].value,
        clazzId:classID,
        fileDate:arr[1],
        filePhone:arr[2],
        fileType:1,
        fileStuAccount:number.innerHTML
    }
    console.log(Json2)
    ajax.post(ajax.myUrl+"stu/addStudent",Json2,function(result){
    }) 
   


}
var cancel = addstudying.getElementsByClassName("cancel")[0];
cancel.onclick = function(){
    addstudying.style.display = "none";
}
var  btn =document.querySelector("button");
btn.onclick = function(){
    var search = document.querySelector("input");
    var Json5 = {
        fileName:search.value,//学生姓名
        pageSize:1,
        pageIndex:1,
        fileType:1
    }
    ajax.post(ajax.myUrl+"stu/searchStu",Json5,function(result){
        //    console.log(result);
           var data = result.dataset.studentList;
        //    console.log(data[0])
            var tbody = document.querySelector("tbody");
            tbody.innerHTML=`
                    <td>${data[0].fileName}</td>
                    <td>${data[0].fileSex}</td>
                    <td>${data[0].clazzName}</td>
                    <td>${data[0].fileDate}</td>
                    <td>${data[0].filePhone}</td>
                    <td>${data[0].fileStatus}</td>
                    <td><div class="remove">修改</div>
                    <div class="delete">删除</div></td>

            `;
            var removes = document.querySelectorAll(".remove");
            var addstudying1 = document.querySelectorAll(".addstudying1")[0];//console.log(addstudying1);
            for(var i=0;i<removes.length;i++){
                localStorage.setItem("fileIds","");
                removes[i].onclick = function(event){
                    for(var j=0;j<removes.length;j++){
                        if(this == removes[j]){
                            // console.log(addstudying1);
                            // 模态框显示
                            addstudying1.style.display = "block";
                            // 获取到本条数据
                            // console.log(data[j]);
                            // 将姓名默认显示到修改页面
                            var username =  addstudying1.querySelector("input");
                            username.value=data[j].fileName;
                            // localStorage.setItem("fileNames",data[j].fileName);
                            localStorage.setItem("fileIds",data[j].fileId);
                            var date = new Date();
                            var month = date.getMonth();
                            if(month<9){
                                month = "0"+(month+1);  //月
                            }
                            var day = date.getDate();
                            var num = Math.floor(Math.random()*100);
                            if(num<10){
                                num = "0"+num;  //月
                            }
                            // //获取账号框
                            var number1 = document.getElementsByClassName("number1")[0];
                            //console.log("br"+month+day+num);
                            number1.innerHTML = "br"+month+day+num;
                           }
                        }
                }
             }
                //点击删除用户
                var deletes = document.getElementsByClassName("delete");
                // console.log(deletes);
                // deletes[0].onclick=function(){
                //     console.log(1)
                // }
                for(var j=0;j<deletes.length;j++){
                    deletes[j].onclick=function(){
                        for(var k=0;k<deletes.length;k++){
                            if(this==deletes[k]){
                                // console.log(data[k].clazzId)
                                // console.log(data[k].fileId)
                                // console.log(data[k].fileType)
                                var Json4={
                                    clazzId: data[k].clazzId,
                                    fileId: data[k].fileId,
                                    fileType:1
                                }
                                ajax.post(ajax.myUrl+"stu/deleteStu",Json4,function(result){
    
                                })
                            }
                        }
                    }
                }
        //点击修改用户模态框中的确定或取消，模态框消失
        //点击确定
            var sure1 = addstudying1.getElementsByClassName("sure1");
            //    console.log(sure1);
            //    console.log(document.querySelector(".addstudyingContent1").querySelector("select"))
       
               sure1[0].onclick = function(){
                clazzIds=null;
                var select=document.querySelector(".updateStudent");
                var updateStudentSex = document.getElementById("updateStudentSex");
                // console.log(updateStudentSex.value)
                // console.log(select.value);
                if(select.value=="JAVA班"){
                    clazzIds="1"
                }else if(select.value=="ui"){
                    clazzIds="2"
                }else if(select.value=="python"){
                    clazzIds="4"
                }
                // console.log(localStorage.getItem("fileIds"))
                
                   var Json3 = {
                       fileId:Number(localStorage.getItem("fileIds")),
                       fileName:document.querySelectorAll("input")[7].value,
                       fileSex:updateStudentSex.value,
                       clazzId:Number(clazzIds),
                       fileDate:document.querySelectorAll("input")[8].value,
                       filePhone:Number(document.querySelectorAll("input")[9].value),
                       fileType:1,
                       fileStuAccount:"21"
                   }
                   console.log(Json3)
                   ajax.post(ajax.myUrl+"stu/updateStu",Json3,function(result){
                       console.log(result);
                   }) 
                 
                   addstudying1.style.display = "none";
            }
       }) 
    }




// //添加用户模态框中的账号
// var date = new Date();
// var month = date.getMonth();
// if(month<9){
//     month = "0"+(month+1);  //月
// }
// var day = date.getDate();
// var num = Math.floor(Math.random()*100);
// if(num<10){
//     num = "0"+num;  //月
// }
// // //获取账号框
// var number = document.getElementsByClassName("number")[0];
// //console.log("br"+month+day+num);
// number.innerHTML = "br"+month+day+num;



// //修改用户模态框中的账号
// var date = new Date();
// var month = date.getMonth();
// if(month<9){
//     month = "0"+(month+1);  //月
// }
// var day = date.getDate();
// var num = Math.floor(Math.random()*100);
// if(num<10){
//     num = "0"+num;  //月
// }
// // //修改在习生模态框中的账号框
// var number1 = document.getElementsByClassName("number1")[0];
// //在习生详情模态框中的账号框
// var number2 = document.getElementsByClassName("number2")[0];
// //console.log("br"+month+day+num);
// number1.innerHTML = "br"+month+day+num;
// number2.innerHTML = "br"+month+day+num;

